home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / utils / adt / not_in.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  3.0 KB  |  124 lines

  1. /*
  2.  * $Header: /private/postgres/src/utils/adt/RCS/not_in.c,v 1.7 1992/02/16 02:17:03 mer Exp $
  3.  *
  4.  * Executes the "not_in" operator for any data type
  5.  *
  6.  * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  7.  * X HACK WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! X
  8.  * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  9.  *
  10.  * This code is the OLD not-in code that is HACKED
  11.  * into place until operators that can have arguments as
  12.  * columns are ******REALLY****** implemented!!!!!!!!!!!
  13.  *
  14.  *
  15.  */
  16.  
  17. #include <stdio.h>
  18.       
  19. #include "tmp/postgres.h"
  20.  
  21.  RcsId("$Header: /private/postgres/src/utils/adt/RCS/not_in.c,v 1.7 1992/02/16 02:17:03 mer Exp $");
  22.  
  23. #include "access/heapam.h"
  24. #include "access/htup.h"
  25. #include "access/relscan.h"
  26. #include "utils/rel.h"
  27. #include "utils/log.h"
  28.  
  29. int my_varattno ARGS((Relation rd , char *a ));
  30.  
  31. /* ----------------------------------------------------------------
  32.  *    
  33.  * ----------------------------------------------------------------
  34.  */
  35. bool
  36. int4notin(not_in_arg, relation_and_attr)
  37.  
  38. int16 not_in_arg;
  39. char *relation_and_attr;
  40.  
  41. {
  42.     HeapTuple tuple;
  43.     ObjectId scan_rel_oid;
  44.     Relation relation_to_scan;
  45.     int left_side_argument, integer_value;
  46.     HeapTuple current_tuple;
  47.     HeapScanDesc scan_descriptor;
  48.     bool dummy, retval;
  49.     int attrid;
  50.     char *relation, *attribute;
  51.     char my_copy[32];
  52.     Datum value;
  53.  
  54.     strcpy(my_copy, relation_and_attr);
  55.  
  56.     relation = (char *) strtok(my_copy, ".");
  57.     attribute = (char *) strtok(NULL, ".");
  58.  
  59.  
  60.     /* fetch tuple OID */
  61.  
  62.     left_side_argument = not_in_arg;
  63.  
  64.     /* Open the relation and get a relation descriptor */
  65.  
  66.     relation_to_scan = amopenr(relation);
  67.     attrid  = my_varattno(relation_to_scan, attribute);
  68.     scan_descriptor = ambeginscan(relation_to_scan, false, NULL, NULL, 1);
  69.     retval = true;
  70.  
  71.     /* do a scan of the relation, and do the check */
  72.     for (current_tuple = amgetnext(scan_descriptor, 0, NULL);
  73.          current_tuple != NULL && retval;
  74.          current_tuple = amgetnext(scan_descriptor, 0, NULL))
  75.     {
  76.         value = HeapTupleGetAttributeValue(current_tuple,
  77.                                            InvalidBuffer,
  78.                                            (AttributeNumber) attrid,
  79.                                            &(relation_to_scan->rd_att),
  80.                                            &dummy);
  81.  
  82.         integer_value = DatumGetInt16(value);
  83.         if (left_side_argument == integer_value)
  84.         {
  85.             retval = false;
  86.         }
  87.     }
  88.  
  89.     /* close the relation */
  90.     amclose(relation_to_scan);
  91.     return(retval);
  92. }
  93.  
  94. bool
  95. oidnotin(the_oid, compare)
  96. ObjectId the_oid;
  97. char *compare;
  98. {
  99.     if (the_oid == InvalidObjectId)
  100.         return false;
  101.     return(int4notin(the_oid, compare));
  102. }
  103.  
  104. /*
  105.  * XXX
  106.  * If varattno (in parser/catalog_utils.h) ever is added to
  107.  * cinterface.a, this routine should go away
  108.  */
  109.  
  110. int
  111. my_varattno ( rd , a)
  112.      Relation rd;
  113.      char *a;
  114. {
  115.     int i;
  116.     
  117.     for (i = 0; i < rd->rd_rel->relnatts; i++) {
  118.         if (!strcmp(&rd->rd_att.data[i]->attname, a)) {
  119.             return(i+1);
  120.         }
  121.     }
  122.     return(-1);
  123. }
  124.